<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      @select="onMenuSelect"
      background-color="#324157"
      text-color="#bfcbd9"
      active-text-color="#20a0ff"
      unique-opened
      :collapse="collapse"
    >
      <el-menu-item index="dashboard" style="font-size: 16px">
        <i class="el-icon-s-home"></i>
        <span slot="title">首页</span>
      </el-menu-item>
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-s-tools"></i>
          <span style="font-size: 16px">系统管理</span>
        </template>
        <el-menu-item index="BuMenRenYuanGuanLi" class="ln_erji"
          >部门和人员管理</el-menu-item
        >
        <el-menu-item index="JueSeGuanLi" class="ln_erji"
          >角色管理</el-menu-item
        >
        <el-menu-item index="JiBenXinXiGuanLi" class="ln_erji"
          >基本信息管理</el-menu-item
        >
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import bus from "../utils/bus";
import { mapState } from "vuex";

export default {
  data() {
    return {
      collapse: false,
    };
  },
  methods: {
    onMenuSelect(name) {
      // if (name === "logout") {
      //   this.logout()
      //   return
      // }
      // this.$store.commit(MENUINDEX, name);
      this.$router.push({ name });
    },

    //权限判断的方法
    hasPerm(name) {
      return this.userinfo.func_names.indexOf(name) > -1;
    },
  },
  computed: {
    ...mapState(["userinfo"]),
    onRoutes() {
      return this.$route.path.replace("/", "");
    },
  },
  created() {
    // 通过 Event Bus 进行组件间通信，来折叠侧边栏
    bus.$on("collapse", (msg) => {
      this.collapse = msg;
      bus.$emit("collapse-content", msg);
    });
  },
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}

.sidebar > ul {
  height: 100%;
}
</style>
